/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.controller;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.purpose.bean.IndexTemplateConfigBean;
import com.koron.purpose.service.api.IndexTemplateConfigService;
import com.koron.purpose.utils.BusinessCode;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "indexTemplateConfig", description = "指标模版配置")
@RestController
@RequestMapping("/indexTemplateConfig")
public class IndexTemplateConfigController {
    @Autowired
    private IndexTemplateConfigService service;

    @ApiOperation("列表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "水司code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "yearNum", value = "年份",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "indexName", value = "配置名称",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页",  dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数",  dataType = "Integer", paramType = "query")
    })
    @RequestMapping(value = "/queryForList.htm", method = RequestMethod.GET)
    public MessageBean queryForList(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore String corpCode, @ApiIgnore Integer yearNum,
                                    @ApiIgnore String indexName, @ApiIgnore Integer page,
                                    @ApiIgnore Integer pageSize) {
        if (null == user) {
            MessageBean msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.queryForList(corpCode, yearNum, indexName, page, pageSize);
    }

    @ApiOperation("根据ID查询指标模版配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/queryById.htm", method = RequestMethod.GET)
    public MessageBean queryById(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore String id) {
        if (null == user) {
            MessageBean msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.queryById(id);
    }

    @ApiOperation("根据ID删除指标模版配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/deleteById.htm", method = RequestMethod.POST)
    @Log(title = "根据ID删除指标模版配置", businessManipulation = BusinessManipulation.DELETE)
    public MessageBean deleteById(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore String id) {
        if (null == user) {
            MessageBean msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.deleteById(id);
    }

    @ApiOperation("新增指标模版配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "水司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "corpName", value = "水司名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "yearNum", value = "年份", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "indexName", value = "配置名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "kpiTemplateIds", value = "考核项模板id字符串(以逗号分隔)", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/insert.htm", method = RequestMethod.POST)
    @Log(title = "新增指标模版配置", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean insert(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                              @ApiIgnore IndexTemplateConfigBean bean, @ApiIgnore String kpiTemplateIds) {
        if (null == user) {
            MessageBean msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.insert(user, bean, kpiTemplateIds);
    }

    @ApiOperation("修改指标模版配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "corpCode", value = "水司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "corpName", value = "水司名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "yearNum", value = "年份", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "indexName", value = "配置名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "kpiTemplateIds", value = "考核项模板id字符串(以逗号分隔)", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/update.htm", method = RequestMethod.POST)
    @Log(title = "修改指标模版配置", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean update(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                              @ApiIgnore IndexTemplateConfigBean bean, @ApiIgnore String kpiTemplateIds) {
        if (null == user) {
            MessageBean msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.update(user, bean, kpiTemplateIds);
    }
}
